home *** CD-ROM | disk | FTP | other *** search
/ One Click 14 / OneClick14.iso / Ferramentas / Convert XLS to Pdf / xls2pdf_setup.exe / {app} / lib / gs_pdfwr.ps < prev    next >
Encoding:
Text File  |  2002-11-19  |  19.1 KB  |  605 lines

  1.  %    Copyright (C) 1996, 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is provided AS-IS with no warranty, either express or
  3. % implied.
  4. % This software is distributed under license and may not be copied,
  5. % modified or distributed except as expressly authorized under the terms
  6. % of the license contained in the file LICENSE in this distribution.
  7. % For more information about licensing, please refer to
  8. % http://www.ghostscript.com/licensing/. For information on
  9. % commercial licensing, go to http://www.artifex.com/licensing/ or
  10. % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. % San Rafael, CA  94903, U.S.A., +1(415)492-9861.
  12.  
  13. % $Id: gs_pdfwr.ps,v 1.21 2002/11/18 19:36:57 alexcher Exp $
  14. % PDF writer additions to systemdict.
  15.  
  16. % This file should be included iff the pdfwrite "device" is included
  17. % in the executable.
  18.  
  19. % ---------------- Predefined configurations ---------------- %
  20.  
  21. % These correspond to the 4 predefined settings in Acrobat Distiller 5,
  22. % plus a "default" setting that doesn't downsample images.
  23.  
  24. /.a2112 [2 1 1 2] readonly def
  25. /.a1111 [1 1 1 1] readonly def
  26. /.standardfonts [
  27.   /Courier /Courier-Bold /Courier-Oblique /Courier-BoldOblique
  28.   /Helvetica /Helvetica-Bold /Helvetica-Oblique /Helvetica-BoldOblique
  29.   /Times-Roman /Times-Bold /Times-Italic /Times-BoldItalic
  30.   /Symbol /ZapfDingbats
  31. ] readonly def
  32.  
  33. % Parameters common to all non-default configurations.
  34. % Note that the default configuration overrides a few of these.
  35. /.defaultImageDict mark
  36.   /QFactor 0.9 /Blend 1
  37.   /HSamples .a2112 /VSamples .a2112
  38. .dicttomark readonly def
  39. /.distillercommon mark
  40.   /AlwaysEmbed []
  41.   /AntiAliasColorImages false
  42.   /AntiAliasGrayImages false
  43.   /AntiAliasMonoImages false
  44.   /ASCII85EncodePages false
  45.   /AutoFilterColorImages true
  46.   /AutoFilterGrayImages true
  47.   /AutoPositionEPSFiles true
  48.   /Binding /Left
  49.   /CalCMYKProfile (None)        % (U.S. Web Coated (SWOP) v2)
  50.   /CalGrayProfile (None)        % (Dot Gain 20%)  
  51.   /CalRGBProfile (None)            % (sRGB IEC61966-2.1)
  52.   /ColorImageDepth -1
  53.   /ColorImageDict .defaultImageDict
  54.   /ColorImageDownsampleThreshold 1.5
  55.   /ColorImageFilter /DCTEncode
  56.   /CompressPages true
  57.   /ConvertImagesToIndexed true
  58.   /DefaultRenderingIntent /Default
  59.   /DetectBlends true
  60.   /DownsampleColorImages true
  61.   /DownsampleGrayImages true
  62.   /DownsampleMonoImages true
  63.   /EmitDSCWarnings false
  64.   /EncodeColorImages true
  65.   /EncodeGrayImages true
  66.   /EncodeMonoImages true
  67.   /EndPage -1
  68.   /GrayImageDepth -1
  69.   /GrayImageDict .defaultImageDict
  70.   /GrayImageDownsampleThreshold 1.5
  71.   /GrayImageFilter /DCTEncode
  72.   /ImageMemory 524288
  73.   /LockDistillerParams false
  74.   /MaxSubsetPct 100
  75.   /MonoImageDepth -1
  76.   /MonoImageDict mark
  77.     /K -1
  78.   .dicttomark readonly
  79.   /MonoImageDownsampleThreshold 1.5
  80.   /MonoImageFilter /CCITTFaxEncode
  81.   /OffOptimizations 0
  82.   /OPM 1
  83.   /Optimize true
  84.   /ParseDSCComments true
  85.   /ParseDSCCommentsForDocInfo true
  86.   /PreserveCopyPage true
  87.   /PreserveHalftoneInfo false
  88.   /sRGBProfile (None)            % (sRGB IEC61966-2.1)
  89.   /StartPage 1
  90.   /SubsetFonts true
  91.   /TransferFunctionInfo /Preserve
  92.   /UseFlateCompression true
  93.   /UsePrologue false
  94. .dicttomark readonly def
  95.  
  96. /.distillersettings mark
  97.  
  98. /default mark
  99.   /AutoRotatePages /PageByPage
  100.   /CannotEmbedFontPolicy /Warning
  101.   /ColorACSImageDict .defaultImageDict
  102.   /ColorConversionStrategy /LeaveColorUnchanged
  103. %  /ColorImageDownsampleType
  104. %  /ColorImageResolution
  105. %  /CompatibilityLevel
  106.   /CreateJobTicket false
  107.   /DoThumbnails false
  108.   /DownsampleColorImages false        % override
  109.   /DownsampleGrayImages false        % override
  110.   /DownsampleMonoImages false        % override
  111.   /EmbedAllFonts true
  112.   /GrayACSImageDict .defaultImageDict
  113. %  /GrayImageDownsampleType
  114. %  /GrayImageResolution
  115. %  /MonoImageDownsampleType
  116. %  /MonoImageResolution
  117.   /NeverEmbed .standardfonts
  118.   /Optimize false            % override
  119.   /PreserveEPSInfo true
  120.   /PreserveOPIComments true
  121.   /PreserveOverprintSettings true
  122.   /UCRandBGInfo /Preserve
  123. .dicttomark readonly
  124.  
  125. /.screenACSImageDict mark
  126.   /QFactor 0.76 /Blend 1 /ColorTransform 1
  127.   /HSamples .a2112 /VSamples .a2112
  128. .dicttomark readonly def
  129. /screen mark
  130.   /AutoRotatePages /PageByPage
  131. %  /CalGrayProfile (None)
  132.   /CannotEmbedFontPolicy /Warning
  133.   /ColorACSImageDict .screenACSImageDict
  134.   /ColorConversionStrategy /sRGB
  135.   /ColorImageDownsampleType /Average
  136.   /ColorImageResolution 72
  137.   /CompatibilityLevel 1.2
  138.   /CreateJobTicket false
  139.   /DoThumbnails false
  140.   /EmbedAllFonts true
  141.   /GrayACSImageDict .screenACSImageDict
  142.   /GrayImageDownsampleType /Average
  143.   /GrayImageResolution 72
  144.   /MonoImageDownsampleType /Average
  145.   /MonoImageResolution 300
  146.   /NeverEmbed .standardfonts
  147.   /PreserveEPSInfo false
  148.   /PreserveOPIComments false
  149.   /PreserveOverprintSettings false
  150.   /UCRandBGInfo /Remove
  151. .dicttomark readonly
  152.  
  153. /ebook mark
  154.   /AutoRotatePages /All
  155. %  /CalGrayProfile (None)
  156.   /CannotEmbedFontPolicy /Warning
  157.   /ColorACSImageDict .screenACSImageDict
  158.   /ColorConversionStrategy /sRGB
  159.   /ColorImageDownsampleType /Bicubic
  160.   /ColorImageResolution 150
  161.   /CompatibilityLevel 1.3
  162.   /CreateJobTicket false
  163.   /DoThumbnails false
  164.   /EmbedAllFonts true
  165.   /GrayACSImageDict .screenACSImageDict
  166.   /GrayImageDownsampleType /Bicubic
  167.   /GrayImageResolution 150
  168.   /MonoImageDownsampleType /Bicubic
  169.   /MonoImageResolution 300
  170.   /NeverEmbed .standardfonts
  171.   /PreserveEPSInfo false
  172.   /PreserveOPIComments false
  173.   /PreserveOverprintSettings false
  174.   /UCRandBGInfo /Remove
  175. .dicttomark readonly
  176.  
  177. /.printerACSImageDict mark
  178.   /QFactor 0.4 /Blend 1 /ColorTransform 1
  179.   /HSamples .a1111 /VSamples .a1111
  180. .dicttomark readonly def
  181. /printer mark
  182.   /AutoRotatePages /None
  183. %  /CalGrayProfile (None)
  184.   /CannotEmbedFontPolicy /Warning
  185.   /ColorACSImageDict .printerACSImageDict
  186.   /ColorConversionStrategy /UseDeviceIndependentColor
  187.   /ColorImageDownsampleType /Bicubic
  188.   /ColorImageResolution 300
  189.   /CompatibilityLevel 1.3
  190.   /CreateJobTicket true
  191.   /DoThumbnails false
  192.   /EmbedAllFonts true
  193.   /GrayACSImageDict .printerACSImageDict
  194.   /GrayImageDownsampleType /Bicubic
  195.   /GrayImageResolution 300
  196.   /MonoImageDownsampleType /Bicubic
  197.   /MonoImageResolution 1200
  198.   /NeverEmbed []
  199.   /PreserveEPSInfo true
  200.   /PreserveOPIComments true
  201.   /PreserveOverprintSettings true
  202.   /UCRandBGInfo /Preserve
  203. .dicttomark readonly
  204.  
  205. /.prepressACSImageDict mark
  206.   /QFactor 0.15 /Blend 1 /ColorTransform 1
  207.   /HSamples .a1111 /VSamples .a1111
  208. .dicttomark readonly def
  209. /prepress mark
  210.   /AutoRotatePages /None
  211.   /CannotEmbedFontPolicy /Error
  212.   /ColorACSImageDict .prepressACSImageDict
  213.   /ColorConversionStrategy /LeaveColorUnchanged
  214.   /ColorImageDownsampleType /Bicubic
  215.   /ColorImageResolution 300
  216.   /CompatibilityLevel 1.3
  217.   /CreateJobTicket true
  218.   /DoThumbnails true
  219.   /EmbedAllFonts true
  220.   /GrayACSImageDict .prepressACSImageDict
  221.   /GrayImageDownsampleType /Bicubic
  222.   /GrayImageResolution 300
  223.   /MonoImageDownsampleType /Bicubic
  224.   /MonoImageResolution 1200
  225.   /NeverEmbed []
  226.   /PreserveEPSInfo true
  227.   /PreserveOPIComments true
  228.   /PreserveOverprintSettings true
  229.   /UCRandBGInfo /Preserve
  230. .dicttomark readonly
  231.  
  232. .dicttomark readonly def
  233.  
  234. % ---------------- End of predefined configurations ---------------- %
  235.  
  236. % Set optimizations for converting PostScript to PDF.
  237. % The ps2pdf* scripts invoke this.
  238. /.setpdfwrite {        % - .setpdfwrite -
  239.         % Set a large VM threshold to reduce garbage collection.
  240.   currentuserparams /VMThreshold get 3000000 .max setvmthreshold
  241.         % Install a level of 'save' to reduce font loading.
  242.   save pop
  243. } bind def
  244.  
  245. % ---------------- pdfmark and DSC processing ---------------- %
  246.  
  247. % Encode values to pass for the /pdfmark or /DSC pseudo-parameter.
  248. /.pdf===dict mark
  249.   /arraytype
  250.    { dup xcheck { ({) (}) } { ([) (]) } ifelse
  251.         % Stack: file obj left right
  252.       4 1 roll 2 index exch writestring () exch
  253.        { exch 2 index exch writestring
  254.      1 index exch pdf===only ( )
  255.        }
  256.       forall pop exch writestring
  257.    } bind
  258.   /packedarraytype 1 index
  259.   /dicttype
  260.    { 1 index (<<\n) writestring
  261.       { 2 index 3 -1 roll pdf===only 1 index ( ) writestring
  262.     1 index exch pdf===only dup (\n) writestring
  263.       }
  264.      forall (>>) writestring
  265.    } bind
  266.   /nametype {
  267.     % If the name string includes any non-regular characters,
  268.     % write it with two preceding and one following null character(s).
  269.     % (Null characters in the name itself are not allowed.)
  270.     % This non-standard escape convention is required for passing names
  271.     % that include non-regular characters, because PostScript provides
  272.     % no way to do this.  The pdf_scan_token procedure in the C code of
  273.     % the pdfwrite driver is currently the only place that recognizes
  274.     % this convention.
  275.     dup .namestring (\000\011\012\014\015 %()/<>[]{}) .stringbreak null ne {
  276.       dup .namestring (\000) .stringbreak null ne {
  277.     /rangecheck signalerror
  278.       } if
  279.       1 index <0000> writestring 1 index exch write===only 0 write
  280.     } {
  281.       write===only
  282.     } ifelse
  283.   } bind
  284. .dicttomark readonly def
  285. /pdf===only {    % <file> <obj> pdf===only -
  286.   .pdf===dict 1 index type .knownget { exec } { write===only } ifelse
  287. } bind def
  288. /.pdfcvbuf 10 string def    % enough for most arguments
  289. userdict /.pdfcvstring () put
  290. /.pdfcvs {        % <obj> .pdfcvs <string>
  291.   currentglobal exch false .setglobal
  292.   /.pdfcvstring () store
  293.         % We can't handle long values yet.
  294.   { pop dup length 0 eq { pop } {
  295.       /.pdfcvstring .pdfcvstring 3 -1 roll concatstrings store
  296.     } ifelse //.pdfcvbuf
  297.   } /NullEncode filter dup 3 -1 roll pdf===only
  298.   closefile
  299.   .setglobal .pdfcvstring
  300. } bind def
  301.  
  302. % Redefine pdfmark to pass the data to the driver.
  303. % We use a pseudo-parameter named /pdfmark whose value is an array:
  304. %    /key1 (value1) ... (CTM) /type
  305. /.pdfputparams {    % -mark- <key1> <value1> ... .pdfputparams <result...>
  306.   currentdevice null false counttomark 1 add 3 roll
  307.         % Don't allow the page device to get cleared....
  308.   {.putdeviceparams} .currentpagedevice pop {.setpagedevice} 3 .execn
  309. } bind def
  310. % Convert relevant operands to strings in an array.
  311. /.pdfcvsloop {        % -mark- values ... markname start step .pdfcvsloop
  312.             %   [values ... ctm markname]
  313.    matrix currentmatrix .pdfcvs 4 1 roll
  314.    counttomark 1 add 2 roll 
  315.    counttomark .localvmarray astore exch pop
  316.    3 1 roll
  317.             % Stack: values start step
  318.    2 index length 3 sub { 2 copy 2 copy get .pdfcvs put pop } for
  319. } bind def
  320. /.pdfcvsall {        % -mark- values ... markname .pdfcvsall <<same>>
  321.   0 1 .pdfcvsloop
  322. } bind def
  323. /.pdfcvseven {        % -mark- key value ... markname .pdfcvseven <<same>>
  324.   1 2 .pdfcvsloop
  325. } bind def
  326. /.pdfcvsnone {        % -mark- values ... markname .pdfcvsnone <<same>>
  327.   100000 1 .pdfcvsloop
  328. } bind def
  329. /.pdfcvsfirst {        % -mark- first values ... markname .pdfcvsfirst<<same>>
  330.   .pdfcvsnone
  331.   dup 0 2 copy get .pdfcvs put
  332. } bind def
  333. % The procedures in the following dictionary are called with the entire
  334. % pdfmark operand list (including the pdfmark name) on the stack;
  335. % they may modify this ad lib.  They must call .pdfcvsxxx.
  336. /.pdfmarkparams mark
  337.     % Unpack a dictionary for PUT, and don't convert stream data.
  338.   /PUT {
  339.     counttomark 3 eq {
  340.       1 index type /dicttype eq {
  341.     pop { } forall /.PUTDICT .pdfcvsall
  342.       } {
  343.     pop dup type /filetype eq {
  344.         % Read the file into a sequence of strings.
  345.         % This isn't great, but it's simple.
  346.       {
  347.         dup 1000 string readstring not { exch exit } if
  348.         exch
  349.       } loop closefile
  350.     } if
  351.     /.PUTSTREAM .pdfcvsfirst
  352.       } ifelse
  353.     } {
  354.       .pdfcvsall
  355.     } ifelse
  356.   } bind
  357.     % Unpack the array for PUTINTERVAL.
  358.   /PUTINTERVAL {
  359.     pop aload pop /.PUTINTERVAL .pdfcvsall
  360.   } bind
  361. .dicttomark readonly def
  362. /.pdfparamerror {    % ? ? ? -mark- ... <errname> <opname> .pdfparamerror -
  363.     counttomark 4 add 2 roll cleartomark pop pop pop
  364.     .systemvar exch signalerror
  365. } bind def
  366. /pdfmark {        % -mark- <key> <value> ... <markname> pdfmark -
  367.   counttomark 1 add copy
  368.   //.pdfmarkparams 1 index .knownget { exec } { .pdfcvsall } ifelse
  369.   mark /pdfmark 3 -1 roll .pdfputparams
  370.   dup type /booleantype ne {
  371.     /pdfmark .pdfparamerror
  372.   } if cleartomark
  373. } odef
  374. userdict /pdfmark .undef
  375. currentdict /.pdfmarkparams .undef
  376.  
  377. % Use the DSC processing hook to pass DSC comments to the driver.
  378. % We use a pseudo-parameter named DSC whose value is an array:
  379. %    /key1 (value1) ... /type
  380. /.pdfdsc_dict 2 dict def
  381. /.pdfdsc {    % <file> <DSC string> <dsc dict> [<prev proc>] .pdfdsc -
  382.   0 get dup null ne { 4 copy exch pop exec } { pop } ifelse 3 -1 roll pop
  383.         % Stack: <dsc string> <dsc dict>
  384.   20 .localvmdict 1 index { 3 copy put pop pop } forall
  385.   3 -1 roll .parse_dsc_comments    % <dsc dict> <dict> <type>
  386.   dup /NOP ne 2 index length 1 gt or {    % Skip unparsed comments
  387.     DEBUG { (**** DSC comment: ) print dup == 1 index === flush } if
  388.     exch mark 4 1 roll {
  389.         % mark <key1> <value1> ... <dsc dict> <type> <key> <value>
  390.       3 index 2 index known {    % Skip the DSC_struct entry
  391.         pop pop
  392.       } {
  393.         .pdfcvs 4 -2 roll
  394.       } ifelse
  395.     } forall exch pop counttomark .localvmarray astore
  396.     mark /DSC 3 -1 roll .pdfputparams
  397.     dup type /booleantype ne {
  398.       /DSC .pdfparamerror
  399.     } {
  400.       cleartomark
  401.     } ifelse
  402.   } {
  403.     pop pop pop
  404.   } ifelse
  405. } bind def
  406. /.initialize_dsc_parser where {
  407.   pop 2 dict dup .initialize_dsc_parser readonly
  408.   currentuserparams /ProcessDSCComment get
  409.   1 array astore    % in case the value is executable
  410.   //.pdfdsc /exec load 4 array astore cvx readonly
  411.   << /ProcessDSCComment 3 -1 roll >> setuserparams
  412. } if
  413.  
  414. % ---------------- {set,current}distillerparams ---------------- %
  415.  
  416. % Define setdistillerparams / currentdistillerparams.
  417. % Distiller parameters are currently treated as device parameters.
  418. /.distillerparamkeys mark
  419.         % General parameters -- all distillers
  420.   /ASCII85EncodePages { }
  421.   /AutoRotatePages { }
  422.   /Binding { }
  423.   /CompressPages { }
  424.   /DefaultRenderingIntent { }
  425.   /DetectBlends { }
  426.   /DoThumbnails { }
  427.   /ImageMemory { }
  428.   /LockDistillerParams { }
  429.   /LZWEncodePages { }
  430.   /OPM { }
  431.   /PreserveHalftoneInfo { }
  432.   /PreserveOPIComments { }
  433.   /PreserveOverprintSettings { }
  434.   /TransferFunctionInfo { }
  435.   /UCRandBGInfo { }
  436.   /UseFlateCompression { }
  437.         % General parameters -- PDF writer
  438.         % StartPage and EndPage are renamed because EndPage
  439.         % clashes with a page device parameter.
  440.   /CoreDistVersion { }
  441.   /CompatibilityLevel { }
  442.         % ****** NOTE: StartPage and EndPage are disabled because
  443.         % ****** EndPage clashes with a page device parameter.
  444. %  /EndPage { exch pop /PDFEndPage exch }
  445.     /PDFEndPage { pop pop }
  446. %  /StartPage { exch pop /PDFStartPage exch }
  447.     /PDFStartPage { pop pop }
  448.   /Optimize { }
  449.   /ParseDSCCommentsForDocInfo { }
  450.   /ParseDSCComments { }
  451.   /EmitDSCWarnings { }
  452.   /CreateJobTicket { }
  453.   /PreserveEPSInfo { }
  454.   /AutoPositionEPSFiles { }
  455.   /PreserveCopyPage { }
  456.   /UsePrologue { }
  457.   /OffOptimizations { }
  458.         % Color sampled image parameters
  459.   /ColorACSImageDict { }
  460.   /AntiAliasColorImages { }
  461.   /AutoFilterColorImages { }
  462.   /ColorImageDepth { }
  463.   /ColorImageDict { }
  464.   /DownsampleColorImages { }
  465.   /ColorImageDownsampleThreshold { }
  466.   /ColorImageDownsampleType { }
  467.   /EncodeColorImages { }
  468.   /ColorImageFilter { }
  469.   /ColorImageResolution { }
  470.         % Color processing parameters
  471.   /CalCMYKProfile { }
  472.   /CalGrayProfile { }
  473.   /CalRGBProfile { }
  474.   /sRGBProfile { }
  475.   /ColorConversionStrategy { }
  476.   /ConvertCMYKImagesToRGB { }
  477.   /ConvertImagesToIndexed { }
  478.         % Grayscale sampled image parameters
  479.   /GrayACSImageDict { }
  480.   /AntiAliasGrayImages { }
  481.   /AutoFilterGrayImages { }
  482.   /GrayImageDepth { }
  483.   /GrayImageDict { }
  484.   /DownsampleGrayImages { }
  485.   /GrayImageDownsampleThreshold { }
  486.   /GrayImageDownsampleType { }
  487.   /EncodeGrayImages { }
  488.   /GrayImageFilter { }
  489.   /GrayImageResolution { }
  490.         % Monochrome sampled image parameters
  491.   /AntiAliasMonoImages { }
  492.   /MonoImageDepth { }
  493.   /MonoImageDict { }
  494.   /DownsampleMonoImages { }
  495.   /MonoImageDownsampleThreshold { }
  496.   /MonoImageDownsampleType { }
  497.   /EncodeMonoImages { }
  498.   /MonoImageFilter { }
  499.   /MonoImageResolution { }
  500.         % Font embedding parameters
  501.   /AlwaysEmbed
  502.    { dup length 0 gt
  503.       { dup 0 get false eq
  504.          { dup length 1 sub 1 exch getinterval exch pop /~AlwaysEmbed exch
  505.          } if
  506.       } if
  507.    }
  508.   /NeverEmbed
  509.    { dup length 0 gt
  510.       { dup 0 get false eq
  511.          { dup length 1 sub 1 exch getinterval exch pop /~NeverEmbed exch
  512.          } if
  513.       } if
  514.    }
  515.   /CannotEmbedFontPolicy { }
  516.   /EmbedAllFonts { }
  517.   /MaxSubsetPct { }
  518.   /SubsetFonts { }
  519. .dicttomark readonly def
  520. /.distillerdevice
  521.  { currentdevice .devicename /pdfwrite eq
  522.     { currentdevice }
  523.     { /pdfwrite finddevice }
  524.    ifelse
  525.  } bind def
  526.  
  527. % Some badly designed PostScript files only expect the current/set
  528. % distillerparams operators to exist in a distiller. Since we have
  529. % this as a runtime option, we enable these operators IFF the
  530. % currentdevice is pdfwrite. Also, we mask their existence in 
  531. % systemdict so that 'where' and 'known' don't show them unless
  532. % the currentdevice is pdfwrite.
  533. /.setdistillerparams {        % <dict> setdistillerparams -
  534.   .distillerdevice //null false mark 4 index {
  535.     //.distillerparamkeys 2 index .knownget { exec } { pop pop } ifelse
  536.   } forall .putdeviceparams
  537.   dup type /booleantype ne {
  538.     /setdistillerparams .pdfparamerror
  539.   } {
  540.     pop pop pop
  541.   } ifelse
  542. } odef
  543. /.currentdistillerparams {    % - currentdistillerparams <dict>
  544.   .distillerdevice //.distillerparamkeys .getdeviceparams .dicttomark
  545.         % Patch StartPage and EndPage
  546.         % ****** NOTE: StartPage and EndPage are disabled because
  547.         % ****** EndPage clashes with a page device parameter.
  548. %  begin /StartPage PDFStartPage /EndPage PDFEndPage
  549. %  currentdict dup /PDFStartPage undef /PDFEndPage undef
  550. %  def def currentdict end
  551. } odef
  552. /setdistillerparams {
  553.   currentdevice .devicename /pdfwrite ne {
  554.     /setdistillerparams /undefined signalerror
  555.   } if
  556.   .setdistillerparams
  557. } bind odef
  558. /currentdistillerparams {
  559.   currentdevice .devicename /pdfwrite ne {
  560.     /currentdistillerparams /undefined signalerror
  561.   } if
  562.   .currentdistillerparams
  563. } bind odef
  564.  
  565. % Patch 'where' so that the distiller operators are only visible
  566. % if the pdfwrite device is the current one.
  567. { currentdevice .devicename /pdfwrite eq {
  568.     .where
  569.   } {
  570.     .where pop dup //systemdict eq { pop false } { true } ifelse
  571.   } ifelse
  572. } bind
  573. { /currentdistillerparams /setdistillerparams /pdfmark }
  574. { .wheredict exch 2 index put } forall pop
  575.  
  576. % Patch 'known' to hide the systemdict version of distiller operators
  577. % unless the currentdevice is pdfwrite.
  578. /known {
  579.   /currentdistillerparams 1 index eq /setdistillerparams 2 index eq or 
  580.   /pdfmark 2 index eq or {
  581.     systemdict 2 index eq {    % only mask the operator in systemdict
  582.       known currentdevice .devicename /pdfwrite ne { pop false } if
  583.   } {
  584.     known
  585.   } ifelse
  586.   } {
  587.     known
  588.   } ifelse
  589. } .bind odef
  590.  
  591. % Set a predefined configuration if PDFSETTINGS is defined.
  592. /PDFSETTINGS where { pop /PDFSETTINGS load } { /default } ifelse
  593. .distillersettings exch get
  594. % Don't override parameters defined on the command line.
  595. dup length .distillercommon length add dict begin
  596. .distillercommon 2 {
  597.   {
  598.     systemdict 2 index known { pop pop } { def } ifelse
  599.   } forall
  600. } repeat
  601. currentdict end .setdistillerparams
  602.